<?
$back_to_url = "order.php";
require("session.php");
require("header.php");
require("config.php");
$navi_page_id = "order";
?>
<script type="text/javascript" src="../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../webkit/dialog/import.js"></script>
<link href="css/home.css" type="text/css" rel="stylesheet" />
<style>
	.login_text { width:230px; height:26px; border:#99cc33 1px solid; font-size:18px; font-family:arial; color:#ff3300}
</style>
</head>
<body style="margin:0px;background:white;" onload="$('#mobile').focus()">
	<? require("top.php"); ?>
	<div style="width:100%;background:#efefef;border-top:#ddd 5px solid; border-bottom:#ddd 5px solid">
		<div style="width:900px; text-align:center; background:white; margin:auto">
			<div style="margin:auto; width:88%">
			<table width=100% cellpadding=3 cellspacing=1 bgcolor="#dddddd">
				<tr bgcolor=white><td colspan=10 align=left><font style="color:gray; font-size:15px">【<b>定单列表</b>】</font>
				</td></tr>
				<tr bgcolor="#f1f1f1">
				<td width="100">定单号</td>
				<td width="80">商品名</td>
				<td>类型</td>
				<td>数量</td>
				<td>单价(元)</td>
				<td>包装</td>
				<td>总金额(元)</td>
				<td>下单时间</td>
				<td>定单状态</td>
				<td width="80">可选操作</td></tr>
				<?
				include("database.php");
				include("pager.php");
				$db = new SimpleDB();

				$page = 1;
				if( isset($_GET['page']) ) {
					$page = intval($_GET['page']);
				}
				$page_size = 20;
				$start_index = ($page-1) * $page_size;
				//$record_count = $db->getOneValue("SELECT count(1) as cnt from jxz_order where user_id=".$_SESSION['user_id']);
				$db->query("SELECT * from crm_order where user_id=".$_SESSION['user_id']." order by id desc limit $start_index, $page_size");
				while($db->moveNext()) {
					$id = $db->f("id");
					$status = $db->f("order_status");
				?>
				<tr bgcolor="white">
					<td><img src="images/icon_house.png" width=16 style="vertical-align:middle"> <?echo $db->f("order_no")?></td>
					<td style='color:green'><?echo $db->f("product")?></td>
					<td><?echo $db->f("type")?></td>
					<td><?echo $db->f("count")?></td>
					<td style='color:red'>￥<?echo $db->f("price")?></td>
					<td><?echo $db->f("box")?></td>
					<td style='color:red'>￥<?echo $db->f("total")?></td>
					<td><?echo $db->f("post_time")?></td>
					<td style="color:<?echo $cfg_order_status_color[$status]?>"><?echo $cfg_order_status[$status]?></td>
					<td>
					<?if($status == -1 ) { // 取消或完成?> 
					<a href='index.php' class="gray">重新购买</a>
					<?} else if($status == 4) {?>
					<a href='javascript:do_comment(<?echo $id?>)' class="gray">消费评价</a>
					<?} else if($status == 3) { // 已配送 ?> 
					<a href='javascript:confirm_order(<?echo $id?>)' class="gray">确认收货</a>
					<?} else { // 受理或配货中?>
					<a href='javascript:cancel_order(<?echo $id?>)' class="gray">取消定单</a>
					<?}?>
					</td>
				</tr>
				<tr bgcolor="white">
					<td align=left colspan="10" style="padding-left:120px">
					<img src="images/icon_mail.png" width=20 style="vertical-align:middle">&nbsp;
					配送信息：
					<font color="#666666"><?echo $db->f("truename")?>，<?echo $db->f("mobile")?>，<?echo $db->f("area")?>，<?echo $db->f("address")?>；
					<?if($db->f("content") != ""){?>(注：<?echo $db->f("content")?>) <?}?></font> <br>

					<img src="images/icon_comment.png" width=20 style="vertical-align:middle">&nbsp;
					消费评价：<font color="#666666">
					<?if($db->f("comment_score") == '') {
						echo "暂无";
					} else {
						$score = $db->f("comment_score");
						echo "<img src='images/star_".$score.".png' width=58 height=13 style='vertical-align:middle' title='".$score."分评价'> ";
						echo $cfg_comment_score[$score];
						if($db->f("comment_desc") != '') {
							echo "；".$db->f("comment_desc");
						}
						echo " @". $db->f("comment_time");
					}?>
					</font>
					<br><br>
					</td>
				</tr>
				<?}?>
				<tr bgcolor=white><td colspan=10 align=center>
				<b style="font-size:15px; color:green">为了让我们的服务可以做得更好，欢迎您对每一次消费体验进行评价！</b>
				<?
				//$pager = new Pager($record_count, $page_size, "class='quicklink'");
				//$pager -> show();
				?>
				</td></tr>
			</table>
			<br><br>
			</div>
		</div>
	</div>
	<script>
		var dlg = null; 
		function closeDlg() { if(dlg!=null) dlg.close(); }

		function do_comment(id) {
			dlg = new Dialog({ title: '消费评价', resizable:false, minimizable:false, maximizable:false}).href("do_comment.php?order_id="+id);
			dlg.show().setSize(400, 260).center();	
		}

		function cancel_order(id) {
			dlg = new Dialog({ title: '取消定单', resizable:false, minimizable:false, maximizable:false}).href("cancel_order.php?order_id="+id);
			dlg.show().setSize(400, 260).center();	
		}

		function confirm_order(id) {
			if(confirm("您确认已收到我们配送的商品吗？")) {
				$.get("order_query.php?action=confirm_order&order_id="+id, function(data){
					if(data == "ok") {
						alert("确认成功！感谢您对我们工作的支持，稍后请给个评价哦 :)");
						window.location.reload();
					}
				});
			}
		}
	</script>
	<? require("bottom.php"); ?>

</body>
</html>